package org.vaadin.nf4v.ext.runtime.beforenav;

import org.vaadin.nf4v.core.navigation.NavigationRequest;
import org.vaadin.nf4v.core.navigation.event.NavigationListener;
import org.vaadin.nf4v.ext.config.beforenav.ExtBeforeNavUtil;

/**
 * Listener provides runtime support for @BeforeNavigation annotation.
 * It notifies all pages, containing methods annotated with @BeforeNavigation
 * with request state events.
 *
 * Such methods may have:
 * 1. no parameters
 * 2. NavigationRequest as parameter
 *
 *
 * Listener must be registered with PAGE_NAVIGATION .. BEFORE_NAVIGATION events.
 */
public class BeforeNavigationListener implements NavigationListener {

    @Override
    public void onNavigation(NavigationRequest request) {
        if (ExtBeforeNavUtil.isNavigationStateSubscribed(request)) {
            ExtBeforeNavUtil.notifyBeforeNavigation(request);
        }
    }
}
